/**
 * Created by luckyjing on 16/3/25.
 */
var Info = {
    SUCCESS: {
        message: "操作成功",
        status: 1000
    },
    ERROR: {
        message: "操作失败",
        status: 1001
    },
    NOLOGIN: {
        message: "未登录",
        status: 1010
    },
    NOAUTH: {
        message: "没有权限",
        status: 1011
    }
};
exports.Info = Info;
exports.getErrorMessage = function (err) {
    if (err.errors) {
        for (var errName in err.errors) {
            if (err.errors[errName].message) {
                return err.errors[errName].message;
            }
        }
    } else {
        return err.errmsg;
    }
};
exports.requireLogin = function (req, res, next) {
    if (!req.isAuthenticated()) {
        return res.json(Info.NOLOGIN);
    } else {
        next();
    }
};
exports.hasAuthorization = function (fn) {
    return function (req, res, next) {
        if (!fn(req, res)) {
            return res.json(Info.NOAUTH)
        } else {
            next();
        }
    };
};
